home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1339 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.0 KB  |  82 lines

  1. Newsgroups: comp.lang.c++
  2. Path: cs.vu.nl!jalten
  3. From: jalten@cs.vu.nl (Alten JP)
  4. Subject: Re: Why can't I use this function prototype????
  5. Nntp-Posting-Host: kits.cs.vu.nl
  6. References: <60ju5934@kbrady.ultranet.com>
  7. Sender: news@cs.vu.nl
  8. Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
  9. Date: Wed, 10 Jan 1996 15:11:33 GMT
  10. X-Newsreader: TIN [version 1.2 PL2]
  11. Message-ID: <DKz0v9.2Lr.0.-s@cs.vu.nl>
  12.  
  13. Ken Brady (kbrady@ultranet.com) wrote:
  14. : I have a header file with something like: 
  15. :  
  16. : /*  pm_app.hpp */ 
  17. : Class PmApplication { 
  18.   ^^^^^
  19.   class PmApplication {
  20.  
  21. :   PmApplication();
  22. :   .... //member and method definitions here 
  23. : }; 
  24. :  
  25. : PmApplication *Application();    //a typical function prototype?? 
  26. : // other function prototypes here 
  27. : // end pm_app.hpp 
  28. :  
  29. : My implementation is, of course, hidden from users of the header file: 
  30. :  
  31. : /*  pm_app.cpp    */ 
  32. : PmApplication *App=NULL;    //a global variable 
  33. :  
  34. : PmApplication *Application() {return App;} 
  35.  
  36. Might want to change this to read:
  37.  
  38.     PmApplication *Application() { 
  39.         if (App) return App;
  40.         static far PmApplication staticApp;
  41.         return &staticApp;
  42.     }
  43. just if you wish, a PmApplication will be created if App equals NULL
  44.  
  45.  
  46. : PmApplication::PmApplication()
  47. : { App = this;}
  48.  
  49. : ... // more implementations 
  50. :  
  51.  
  52. :  
  53. : So, I try to use this function:
  54. :  
  55. : /* myapp.cpp  */ 
  56. : #include "pm_app.hpp" 
  57. :  
  58. : void MyProcedure()  
  59. : { ... 
  60. :   PmApp *A=Application();        //won't compile!! 
  61.     ^^^^^
  62.     PmApplication* A = Application();    // compiles fine under Borland
  63. :   ... 
  64. : } 
  65. :  
  66.  
  67. Which compiler do you use? Is there a conflict with Application()
  68. and any other (library-) functions or classes?
  69. Try changing Application() to HeyThisIsMyApplication() see
  70. what happens...
  71.  
  72. Good Luck
  73.  
  74. Jelle Paul
  75.  
  76.  
  77. --
  78. +-------------------------------------------------------+
  79. | Jelle Paul Alten                |   jalten@cs.vu.nl   |
  80. | Vrije Universiteit Amsterdam    |                     |
  81. +-------------------------------------------------------+
  82.